package com.omesoft.hksnore.me;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.omesoft.hksnore.R;
import com.omesoft.hksnore.util.myactivity.MyActivity;
import com.omesoft.hksnore.util.omeview.ProgressWebView;
import com.omesoft.hksnore.util.titlebar.MyTitlebarUtil;


/**
 * Created by Omesoft on 2017/3/15.
 */

public class KnowledgeActivity extends MyActivity {
    private ProgressWebView webView;
    private String url = "http://ask.medix.cn/wenda.html?title=%E9%BC%BE%E7%97%87&tid=323";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.snore_activity_knowledge);
        initTitleBar();
        initView();
    }

    @Override
    protected void initTitleBar() {
        super.initTitleBar();
        MyTitlebarUtil.showTitleName(activity, R.string.me_knowledge_base);
        MyTitlebarUtil.showIbLeft(activity, R.mipmap.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void initView() {
        super.initView();
        webView = (ProgressWebView) findViewById(R.id.knowledge_progressbar);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setBlockNetworkImage(false);
        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
            webView.goBack();//点击返回键返回上一个地址
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
